<?php
/**
 * @description 概念股票
 * @author 陈武<chenwu@myhexin.com>
 * @history
 *         2020/4/21 22:56 create
 */
namespace Home\Model;
class RelationModel
{
    /**
     * @description 添加数据
     * @param array $data 具体数据
     * @return mixed
     */
    public function add($data)
    {
        $codeInfo = M('stock')->where(['id' => $data['save_code']])->find();
        $conceptInfo = M('concept')->where(['id' => $data['save_concept']])->find();
        $data = [
            'concept_id' => $conceptInfo['id'],
            'concept_name' => $conceptInfo['name'],
            'code' => $codeInfo['code'],
            'code_name' => $codeInfo['name'],
            'explain' => $data['explain'],
            'best' => '',
            'ctime' => time(),
            'rtime' => time()
        ];
        return M('concept_stock')->add($data);
    }

    /**
     * @description 新增数据
     * @param array $data 具体数据
     * @return mixed
     */
    public function insert($data)
    {
        return M('concept_stock')->add($data);
    }

    /**
     * @description 删除数据
     * @param array $where 条件
     * @return mixed
     */
    public function del($where)
    {
        return M('concept_stock')->where($where)->delete();
    }

    /**
     * @description 搜索
     * @param int $page
     * @param int $size
     * @param array $where
     * @return mixed
     */
    public function search($page = 1, $size = 10, $where = [])
    {
        return M('concept_stock')->page($page)->limit($size)->where($where)->select();
    }

    /**
     * @description 总条数
     * @param array $where
     * @return int
     */
    public function total($where)
    {
        $result = M('concept_stock')->field('id')->where($where)->select();
        return $result?count($result):0;
    }
}